package cn.com.b2office.dao.hibernate;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import cn.com.b2office.dao.DictDao;
import cn.com.b2office.domain.DictData;

public class DictDaoHibernateImpl extends HibernateDaoSupport implements
		DictDao {

	private DictData getDictData(int id) {
		return (DictData) getHibernateTemplate().get(DictData.class, id);
	}

	@SuppressWarnings("unchecked")
	private List<DictData> findDictData(int typeId) {
		List<DictData> list = null;
		Session s = getSession();
		try {
			Query query = s.createQuery("from DictData where typeid=:typeId")
					.setInteger("typeId", typeId);
			query.setCacheable(true);
			list = query.list();
		} catch (RuntimeException e) {
			throw e;
		} finally {
			releaseSession(s);
		}
		return list;
	}

	public List<DictData> findAllInvoices() {
		return findDictData(10);
	}

	public List<DictData> findAllPwdQuestions() {
		return findDictData(4);
	}

	public DictData getInvoice(int id) {
		return getDictData(id);
	}

	public DictData getPwdQuestion(int id) {
		return getDictData(id);
	}

}
